<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数">
<input type="button" value="猜一猜" onclick="f()">
<div></div>

<script>
    let n = parseInt(Math.random() * 100 + 1);
    let d = document.querySelector("div");
    let i = document.querySelector("input");
    let count = 0;
    d.innerText = "答案为:"+n;

    function f() {

      count++;
      if (i.value > n) {
        d.innerText = "猜大了!"
      } else if (i.value < n) {
        d.innerText = "猜小了!"
      } else {
        d.innerText = "猜中了!一共猜了" + count + "次!";
        n = parseInt(Math.random()*100+1);
        count=0;
      }
      i.value="";
    }

</script>
</body>
</html>